__author__="Administrator"
__date__ ="$2010-5-27 17:43:56$"

import socket
import httpyd

class httpd:
    def __init__(self,config):
        self.config = config
        if(self.config.get("host") == None):
            self.config["host"] = "127.0.0.1"
        if(self.config.get("port") == None):
            self.config["port"] = 80
        self.sock = None

    def start(self):
        self.sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        self.sock.bind(self.config["host"])
        self.sock.listen(self.config["port"])
        while(True):
            s,addr = self.sock.accept()
            req = httpyd.Request(s)
            response = httpyd.Response(s)
            req.getRequest()
            file = req.getRequestFile()
            response.send(file)

    
